package com.example.xianji.activity;

import org.json.JSONException;
import org.json.JSONObject;

import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Main_TiWen_DetailsActivity extends Activity {
    /************************提问详情页面*************************/
    private RelativeLayout tiwen_details_back;
    //    private SharedPreferences sp;
//    private Editor ed;
    private TextView my_question, textview_xuqiu, tiwen_detail_time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__ti_wen__details);

        tiwen_details_back = (RelativeLayout) findViewById(R.id.tiwen_details_back);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        my_question = (TextView) findViewById(R.id.my_question);
        textview_xuqiu = (TextView) findViewById(R.id.textview_xuqiu);
        tiwen_detail_time = (TextView) findViewById(R.id.tiwen_detail_time);


        tiwen_details_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Main_TiWen_DetailsActivity.this.finish();
            }
        });
        XJApplication.cachThreadPool.execute(new Runnable() {

            @Override
            public void run() {
                get_tiwen_details();
            }
        });
    }

    public void get_tiwen_details() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("dqid", getIntent().getIntExtra("tiwen_id", 0) + "");

        httpUtils.send(HttpMethod.POST, Contant.tiwen_details, parms,
                new RequestCallBack<String>() {
                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject response = new JSONObject(arg0.result);
                            if (response.getInt("status") == 1) {
                                JSONObject object = response.getJSONObject("data");
                                my_question.setText("我:" + "   " + object.getString("query"));
                                textview_xuqiu.setText("需求方:" + "   " + object.getString("detail"));
                                tiwen_detail_time.setText(object.getString("created_at"));
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }
}
